//twopts.txt - Like basic monst, but this character spends all its time oscillating 
// between two nav points.
// Memory Cells:
//   Cell 0 - Dialogue node
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.
//	 Cell 3 - The nav point the character marches to. If -1, stand still
//   Cell 4 - If 1, this is a hunter

begincreaturescript;

variables;

short i,target;
short path_a_or_b = 0;
short last_walk;
short adjust = 0;
short last_abil;

body;

beginstate INIT_STATE;
	last_walk = get_current_tick();
	last_abil = get_current_tick();
	
	set_aggression(ME,10);
	
	set_attack_bonus(ME,6);
	set_resistance(ME,0,30);
	set_resistance(ME,1,30);
	set_resistance(ME,2,30);
	set_resistance(ME,3,30);
	
	if (get_memory_cell(4) > 0)
		set_aggression(ME,8);
	if (get_memory_cell(3) < 0) 
		set_aggression(ME,8);
		
	break;

beginstate DEAD_STATE;
	if (get_memory_cell(4) == 0) {
		inc_flag(8,8,1);
		if ((gf(8,8) == 8) && (num_chars_in_group(1) > 0)) {
			begin_talk_mode(6);
			}
		}
	
break;

beginstate START_STATE; 
	if (gf(8,17) > 0)
		set_aggression(ME,7);
	if ((adjust == 0) && (gf(8,16) > 0)) {
		adjust = 1;
		set_attack_bonus(ME,0);
		set_resistance(ME,0,0);
		set_resistance(ME,1,0);
		set_resistance(ME,2,0);
		set_resistance(ME,3,0);
		
		}
	
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
	if (get_memory_cell(3) >= 0) {
		if (gf(8,2) == 0) {
			if (dist_to_nav_point(ME,get_memory_cell(3)) >= 3)
				approach_nav_point(ME,get_memory_cell(3),2);	
			}
			else return_to_start(ME,2);
		}
		

	if ((get_memory_cell(4) > 0) && (gf(8,8) >= 8) && (get_attitude(ME) >= 10) && (dist_to_pc() <= 40)) {
		set_foe_target(ME,pc_num());
		set_state(3);
		}
		
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);

	if ((creature_type(ME) == 177) && (is_combat()) && 
	  (tick_difference(last_abil,get_current_tick()) > 1)) {
		run_char_animation(2,1,35);	
	
		place_particle_num(ME,1,4,8);
		print_named_str(ME,"radiates a cloud of searing energy.");
		pc_heard_sound_delay(179,250);						
		create_missile_spiral(155,40,6,2);
		damage_nearby(get_ran(get_level(ME),1,8),6,1,0);
		status_nearby(2,6,20,0);

		last_abil = get_current_tick();
		end();
		}
		
	do_attack();
break;

beginstate TALKING_STATE;

	break;